package com.htu.courseService.auth.strategy;

import cn.dev33.satoken.stp.SaLoginConfig;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSON;
import com.htu.courseService.auth.vo.LoginRequest;
import com.htu.courseService.auth.vo.LoginResponse;
import com.htu.courseService.user.vo.UserInfo;

/**
 * Created By JNNarrator on 2024/9/7 16:42
 * email: jiangn09@chinatelecom.cn
 */
public interface LoginStrategy {
	LoginResponse login(LoginRequest request);
	default LoginResponse loginSuccess(UserInfo userInfo){
		String headIcon = userInfo.getHeadIcon();
		userInfo.setHeadIcon(null);
		SaLoginModel saLoginModel = SaLoginConfig
				.setExtra("userInfo", JSON.toJSONString(userInfo));
		StpUtil.login(userInfo.getUsername(),saLoginModel);
		SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
		userInfo.setHeadIcon(headIcon);
		return new LoginResponse(userInfo,tokenInfo);
	}
}
